package genedit.gui.propertyDialogs;

import genedit.gui.GMainFrame;
import genedit.model.graph.classModel.AggregationLink;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class AggregationLinkDialog  extends JDialog {
	
	protected JFrame parent;
	protected GMainFrame mf = GMainFrame.getInstance();
	protected AggregationLink linkAggregation;
	protected JButton btnOkDialog;
	protected PanelDetailAggregationLink panelAggregation;
	
	public AggregationLinkDialog(JFrame parent, AggregationLink link) {
		super(parent, true);
		
		linkAggregation = link;
		this.parent = parent;
		
		setTitle(linkAggregation.getName());		;
		setSize(mf.getWidth()/3, 2*mf.getHeight()/5);
		setLocationRelativeTo(parent);
		
		panelAggregation = new PanelDetailAggregationLink(linkAggregation);
		add(panelAggregation, BorderLayout.CENTER);
		
		JPanel panSouth = new JPanel();
		panSouth.setLayout(new BoxLayout(panSouth, BoxLayout.PAGE_AXIS));
		 btnOkDialog = new JButton(GMainFrame.getInstance().getResourceBundle().getString("btnOk"));
		 btnOkDialog.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
						linkAggregation.setName(panelAggregation.getTxtName().getText());
						linkAggregation.setMultiplicityStart((String)panelAggregation.getCmbMultiplicity1().getSelectedItem());
						linkAggregation.setMultiplicityEnd((String)panelAggregation.getCmbMultiplicity2().getSelectedItem());
						linkAggregation.setRoleNameStart((String)panelAggregation.getTxtRoleName1().getText());
						linkAggregation.setRoleNameEnd((String)panelAggregation.getTxtRoleName2().getText());
						setVisible(false);
			}
		});
		 btnOkDialog.setAlignmentX( 
				Component.CENTER_ALIGNMENT); 
		panSouth.add(Box.createVerticalGlue()); 
		panSouth.add(btnOkDialog); 
		panSouth.add(Box.createVerticalGlue());;
		add(panSouth, BorderLayout.SOUTH);
		
		pack();
	}
	
	
}
